# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Guillaume Horel <guillaume.horel@gmail.com>

pkgname=arrow
pkgver=14.0.0
pkgrel=1
pkgdesc="Columnar in-memory analytics layer for big data."
arch=(loong64 x86_64)
url="https://arrow.apache.org"
license=(Apache)
depends=(apache-orc brotli bzip2 gflags grpc google-glog libutf8proc
         lz4 openssl protobuf re2 snappy thrift zlib zstd)
provides=(parquet-cpp)
conflicts=(parquet-cpp)
makedepends=(boost clang cmake flatbuffers git gmock rapidjson xsimd)
source=(https://archive.apache.org/dist/${pkgname}/${pkgname}-${pkgver}/apache-${pkgname}-${pkgver}.tar.gz{,.asc}
        git+https://github.com/apache/parquet-testing.git
        git+https://github.com/apache/arrow-testing.git)
sha512sums=('9e1f8179e37279a47baa3587c66d8b385362478d998601b5f0a8bb2f360ec8cdb954705f397dac413ac1411e72d4dd740e3785823cc063ca35eb80585d2eedf2'
            'SKIP'
            'SKIP'
            'SKIP')
validpgpkeys=(265F80AB84FE03127E14F01125BCCA5220D84079  # Krisztian Szucs (apache) <szucs.krisztian@gmail.com>
              08D3564B7C6A9CAFBFF6A66791D18FCF079F8007) # Kouhei Sutou <kou@cozmixng.org>

build(){
  CC=clang \
  CXX=clang++ \
# clang didn't support -mlsx
  CFLAGS=${CFLAGS/-mlsx /}
  CXXFLAGS=${CXXFLAGS/-mlsx /}
  CFLAGS=${CFLAGS/-fstack-clash-protection/}
  CXXFLAGS=${CXXFLAGS/-fstack-clash-protection/}
  cmake \
    -B build -S apache-${pkgname}-${pkgver}/cpp \
    -DCMAKE_INSTALL_PREFIX="/usr" \
    -DCMAKE_INSTALL_LIBDIR="lib" \
    -DCMAKE_BUILD_TYPE=Release \
    -DARROW_BUILD_STATIC=OFF \
    -DARROW_DEPENDENCY_SOURCE=SYSTEM \
    -DARROW_BUILD_TESTS=ON \
    -DARROW_COMPUTE=ON \
    -DARROW_CSV=ON \
    -DARROW_SUBSTRAIT=ON \
    -DARROW_FLIGHT=ON \
    -DARROW_FLIGHT_SQL=ON \
    -DARROW_GANDIVA=OFF \
    -DARROW_HDFS=ON \
    -DARROW_IPC=ON \
    -DARROW_JEMALLOC=ON \
    -DARROW_ORC=ON \
    -DARROW_PARQUET=ON \
    -DARROW_TENSORFLOW=ON \
    -DARROW_USE_GLOG=ON \
    -DARROW_WITH_BROTLI=ON \
    -DARROW_WITH_BZ2=ON \
    -DARROW_WITH_LZ4=ON \
    -DARROW_WITH_SNAPPY=ON \
    -DARROW_WITH_ZLIB=ON \
    -DARROW_WITH_ZSTD=ON \
    -DPARQUET_REQUIRE_ENCRYPTION=ON \
    -Wno-dev
  make -C build
}

check(){
  PARQUET_TEST_DATA="${srcdir}"/parquet-testing/data \
  ARROW_TEST_DATA="${srcdir}"/arrow-testing/data \
  ctest --test-dir build --output-on-failure
}

package(){
  DESTDIR="$pkgdir" cmake --install build
  find "${pkgdir}"/usr/lib/ -name '*testing*' -delete
}
